package com.yzc.menu;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/menu")
@RequiredArgsConstructor
public class MenuController {


    final MenuBeanServiceImpl menuBeanService;

    /**
     * 获取用户数据
     *
     * @return
     */
    @RequestMapping("/loadAll.do")
    public List<MenuBean> loadAll(){
        return  menuBeanService.loadAll();
    }

    @RequestMapping("/loadMenuList.do")
    public List<MenuBean> loadMenuList() {
        return menuBeanService.loadMenuList();
    }

    /**
     * 修改用户数据
     *
     * @return
     */
    @RequestMapping("/update.do")
    public Map updateInfo(@RequestBody MenuBean menuBean) {
        return menuBeanService.updateInfo(menuBean);
    }

    /**
     * 更新用户数据
     *
     * @return
     */
    @RequestMapping("/save.do")
    public Map save(@RequestBody MenuBean bean) {
        //pass加密，可以，但是不合理
        return menuBeanService.saveInfo(bean);
    }

    /**
     * 删除用户数据
     *
     * @return
     */
    @RequestMapping("/deleteInfo.do")
    public Map deleteInfo(int id) {
        return menuBeanService.deleteInfo(id);
    }

    /**
     * 查询用户数据
     *
     * @return
     */
    @RequestMapping("/selectInfos.do")
    public List<MenuBean> selectInfos(String name) {
        return menuBeanService.selectInfosByWhere(name);
    }

    /**
     * 根据id查询
     *
     * @return
     */
    @RequestMapping("/getInfo.do")
    public MenuBean getInfo(String id) {
        return menuBeanService.getInfoById(id);
    }

    @RequestMapping("/loadMenuTree.do")
    public List<MenuBean> loadMenuTree(){return menuBeanService.loadMenuTree();}

    @RequestMapping("/loadMenuTreeByUserid.do")
    public List<MenuBean> loadMenuTreeByUserid(int userid){
        return menuBeanService.loadMenuTreeByUserid(userid);
    }

}
